package com.model.model01.demo01;

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        try{
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入第一个数字: ");
            String number1 = sc.next();

            System.out.println("请输入运算符: ");
            String operate = sc.next();

            System.out.println("请输入第二个数字: ");
            String number2 = sc.next();

            double result = 0.0;
            switch (operate) {
                case "+" : result = Double.parseDouble(number1) + Double.parseDouble(number2); break;
                case "-" : result = Double.parseDouble(number1) - Double.parseDouble(number2); break;
                case "*" : result = Double.parseDouble(number1) * Double.parseDouble(number2); break;
                case "/" :
                    if ("0".equals(number2)) {
                        System.out.println("除数不能为0");
                        break;
                    }
                    result = Double.parseDouble(number1) / Double.parseDouble(number2);
                    break;
                default: System.out.println("暂不支持运算符");
            }

            System.out.println("运算结果：" + result);
        } catch (Exception e) {
            System.out.println("程序异常：" + e.getMessage());
        }

    }

}
